package io.renren.controller;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.mapper.EntityWrapper;

import io.renren.common.utils.R;
import io.renren.entity.CCSTypeEntity;
import io.renren.response.CCSTypeResponse;
import io.renren.service.CCSTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 选题类型接口
 * @author SongR
 *
 */
@RestController
@RequestMapping("/api")
@Api(tags = "选题类型接口")
public class ApiTypeController {

	@Autowired
	CCSTypeService service;	
	
	/**
	 * 获取选题类型
	 * @return
	 */
	@GetMapping("getType")
	@ApiOperation(value = "获取选题栏目",notes="用于选题添加", response = CCSTypeResponse.class)
	public R getType(){
		List<CCSTypeEntity> types = service.selectList(new EntityWrapper<CCSTypeEntity>().eq("type_status", 1));
		List<CCSTypeResponse> tr = new ArrayList<CCSTypeResponse>();	
		for (CCSTypeEntity t : types) {
			CCSTypeResponse type = new CCSTypeResponse();
			BeanUtils.copyProperties(t, type);
			tr.add(type);
		}
		return R.ok().put("result", tr);
	}
	
}
